/*
* name;
*/
class MapView extends ui.map.MapViewUI {
    constructor() {
        super();
        //初始化
		for (let i = 1; i <= 13; i++) {
			this["pos" + i + '_b'].visible = false;
            this["pos" + i + '_t'].visible = false;
			this["pos" + i].on(Laya.Event.CLICK, this, this.upgradeTower,[i]);
            this["pos" + i + '_t'].on(Laya.Event.CLICK, this, this.upgradeTower,[i]);
		}
        //初始化
        this.tower1.visible = false;
        this.tower2.visible = false;
        this.tower1.on(Laya.Event.CLICK, this, this.buildTower,['1']);
        this.tower2.on(Laya.Event.CLICK, this, this.buildTower,['2']);
    }

	public upgradeTower(index): void{
		var isVisible = this["pos" + index + '_b'].visible;
		for (let i = 1; i <= 13; i++) {
			this["pos" + i + '_b'].visible = false;
		}
		this["pos" + index + '_b'].visible = !isVisible;

        if (this["pos" + index + '_b'].visible == true) {
            console.log('true');
            this.tower1.visible = true;
            this.tower2.visible = true;
        }else{
            console.log('false');
            this.tower1.visible = false;
            this.tower2.visible = false;
        }

	} 

    public buildTower(index):void{
        var markIndex = -1;
       for (let i = 1; i <= 13; i++) {
			if (this["pos" + i + '_b'].visible == true) {
                markIndex = i;
                console.log('markIndex = '+markIndex);
            }
		}
        this["pos" + markIndex + '_t'].visible = true;
        var img = this["pos" + markIndex + '_t'];
        img.skin = 'role/tower'+index+'_1.png';   

    }  


}